<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
class AppRoles {
    var $id;
    var $role_name;
    var $role_desc;

    function __construct($id,$role_name,$role_desc){
        $this->role_name=$role_name;
        $this->role_desc=$role_desc;
        $this->id= $id;
    }
    function open($id){
        global $db;
        $sql="select * from app_roles where id=$id";
        $row=$db->fetch_row($sql);
        if (!empty($row)){
            extract($row);
            $this->role_name=$role_name;
            $this->role_desc=$role_desc;

        }
    }

    function openAll(){
        $sql="select * from app_roles order by id asc";
        $result=$db->query($sql);
        return $db->fetch_array($result);
        
    }

    function insert(){
    global $db;
    $sql="insert into app_roles values (null,'{$this->role_name}','{$this->role_desc}')";
    $db->query($sql);
    return mysql_insert_id();
    }

    function update(){
        global $db;
        $sql="update app_roles set role_name='{$this->role_name}',role_desc='{$this->role_desc}' where id={$this->id}";
        $db->query($sql);
    }

    function delete(){
        global $db;
        $sql="delete from app_roles where id=".$this->id;
        $db->query($sql);
    }

}
?>
